package com.longlong.controller;

import com.longlong.domain.User;
import com.longlong.mvc.annotation.RequestMapping;
import com.longlong.mvc.annotation.RequestParam;
import com.longlong.mvc.annotation.ResponseBody;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;

/**
 * 升级后的 controller
 * 一个请求 对应 一个方法
 *
 * @author longlong
 * @date 2025/1/25
 */
@Slf4j
public class AtmController {

    /**
     * 测试 基本类型的参数
     */
    @RequestMapping("login")
    public String login(@RequestParam("name") String name, @RequestParam("pass") int pass) {
        log.info("AtmController login method start");
        log.info("解析参数...");
        log.info("name = " + name);
        log.info("pass = " + pass);
        log.info("AtmController login method end");
        return "welcome.jsp";
    }

    /**
     * 测试 domain 对象类型的参数
     * @param user 实体对象
     * @return 返回值
     */
    @RequestMapping("query")
    @ResponseBody
    public String query(User user) {
        log.info("AtmController query method start");
        String name = user.getName();
        Integer pass = user.getPass();
        log.info("name = " + name);
        log.info("pass = " + pass);
        log.info("AtmController query method end");
        return "welcome.jsp";
    }

    /**
     * 测试 map 类型的参数
     */
    @RequestMapping("register")
    @ResponseBody
    public User register(HashMap<String, Object> map) {
        log.info("AtmController register method start");
        log.info("解析参数...");
        log.info(map.toString());
        log.info("AtmController register method end");
        User user = new User();
        user.setName("zhangsan");
        user.setPass(123);
        return user;
    }
}
